﻿using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;

public class UICharacter : MonoBehaviour,IDropHandler
{

    public UICharacterEquipRender[] equipRenders; 



    public void Refresh()
    {
        RoleData roleData = GameData.GetCurRoleData();

        for (int i = 0; i < equipRenders.Length; i++)
        {
            if (roleData.equips.ContainsKey((int)equipRenders[i].slot))
            {
                equipRenders[i].SetData(roleData.equips[(int)equipRenders[i].slot]);
            }
            else
            {
                equipRenders[i].SetData(null);
            }
        }
    }

    public void OnDrop(PointerEventData eventData)
    {
        if (eventData.pointerDrag == null)
            return;

        UIBagItemRender bagItemRender = eventData.pointerDrag.GetComponent<UIBagItemRender>();
        if (bagItemRender == null)
            return;
        ItemData itemData = bagItemRender.data;
        if (itemData == null)
            return;
        ItemInfo itemInfo = itemData.GetItemInfo();
        if (itemInfo.type != 2)
            return;
        GameData.Equip(itemData.id);

        Refresh();
    }
}
